<template>
	<!-- 收藏夹 -->
	<view :class="pageClass" :style="pageStyle" v-if="pageReady">
		<view class="index">
			<moxi-nav :set="navSet"></moxi-nav>
			<view class="boxs">
				<view class="box" v-for="(item, index) in data" :key="index" @click="goProduct(item.pid)">
					<view class="left"  v-if="item.img&&item.img.length">
						<img :src="item.img" alt="" style="object-fit: cover">
					</view>
					<view class="right">
						<view class="top">
							<view class="name">{{item.title}}</view>
						</view>
						<view class="bottom">
							<view class="price">&yen;<view class="money">{{item.price}}</view>
							</view>
							<view class="btn" style="background: orangered;" @click.stop="del(item.id)">删除</view>
						</view>
					</view>
				</view>
			</view>
			<view style="display: flex;flex-direction: row;justify-content: center;">
			<u-divider style="padding-bottom: 10px;" text="没有更多内容了" v-if="!data.length"></u-divider>
			</view>
		</view>
		<moxi-tabbar :set="tabbar" v-if="tabbar.index_id"></moxi-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data:[]
			}
		},
		created() {
			this.get()
		},
		methods: {
			get(){
				this.moxiPost('/plugin/info/user/product/get_collect', {}, (data)=> {
					this.data = data.data;
				})
			},
			leftClick() {
				uni.navigateBack({
					delta: 1
				})
			},
			navigateBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			goProduct(pid) {
				this.navto('plugin_info/product_con?id='+pid)
			},
			del(id){
				let self = this;
				uni.showModal({
					title: '确认要删除该收藏吗？',
					content: '删除后无法恢复，请谨慎操作！',
					success: function (res) {
						if (res.confirm) {
							self.moxiPost('/plugin/info/user/product/del_collect', {id:id}, function(data) {
								self.msg(data.hint);
								self.get()
							})
						
						} else if (res.cancel) {
							
						}
					}
				});
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.boxs {
		width: 94%;
		margin: 20px auto;

		.box {
			width: 100%;
			display: flex;
			// justify-content: space-between;
			align-items: center;
			margin-bottom: 10px;
			padding: 6px 10px;
			border-radius: 5px;
			box-sizing: border-box;
			background-color: #fff;

			// &:nth-last-of-type(1) {
			// 	margin-bottom: 16px;
			// }

			.left {
				width: 80px;
				height: 80px;

				img {
					width: 100%;
					height: 100%;
					object-fit: cover;
				}
			}

			.right {
				width: calc(100% - 100px - 10px);
				margin-left: 10px;

				.top {
					margin-bottom: 10px;

					.name {
						font-size: 18px;
						font-weight: bold;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
					}
				}

				.bottom {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.price {
						display: flex;
						align-items: baseline;
						font-size: 14px;
						color: #f00;

						.money {
							margin-left: 2px;
							font-size: 18px;
						}
					}

					.btn {
						padding: 1px 10px;
					
						border-radius: 20px;
						color: #fff;
					}
				}
			}
		}
	}

	.index {
		width: 100%;
		height: 100vh;
		background-color: #eee;
		overflow: auto;
	}
</style>